import router from "./router/index.js";

//全局前置守卫
router.beforeEach((to, from, next) => {
  let token = "123";

  //如果登录
  if (token) {
    //如果在登录的情况下访问登录页面或者根页面，则前往home主页
    if (to.path == "/login" || to.path == "/") {
      next({ path: "/home" });
    } else {
      //否则直接放行
      next();
    }
  } else {
    //如果未登录，可以前往登录页面或者根页面
    if (to.path == "/login" || to.path == "/" || to.path == "/404") {
      next();
    } else {
      //否则前往登录页面
      next({ path: "/" });
    }
  }
});
